<?php
if ($_SERVER['PHP_SELF'] == __FILE__) { header('location: ?'); exit(); }
if (!ADMIN) { perkelti('?'); }

echo "<div class=\"title\">HomePage</div>";
echo "<div class=\"srasas\">".$_SERVER["HTTP_HOST"]."</div>";
echo "<div class=\"title\">Serverio apkrovimas</div>";
echo "<div class=\"srasas\">Svetainė naudoja ".((function_exists('memory_get_usage')) ? baitai(memory_get_usage()) : 'klaida!')."</div>";
echo "<div class=\"srasas\">Iš jai skirtų: ".ini_get('memory_limit')."</div>";
if (ADMIN) {
	$funkcijos = get_defined_functions();
	$funkcijos = $funkcijos['user'];
	echo "<div class=\"title\">Funkcijos</div>";
	foreach($funkcijos as $key => $val) {
		echo "<div class=\"sarasas\">$key. <b>$val();</b></div>";
	}
	unset($funkcijos,$key,$val);
	echo "<hr/>";
	//Debug("browser",get_defined_vars());
}
//print_rr(get_defined_vars());
Debug(get_defined_vars());
function Debug($defined_vars,$email="undefined") {
	$ignorelist=array("HTTP_POST_VARS",
	"HTTP_GET_VARS",
	"sql",
	"_FILES",
	"_REQUEST",
	"_COOKIE",
	"_POST",
	"_SERVER",
	"_GET",
	"zp",
	"valk",
	"im",
	"x",
	"meniu",
	"menu",
	"meniu_forumas",
	"meniu_pamokos",
	"meniu_straipsniai",
	"meniu_refer",
	"meniu_atsiusti",
	"meniu_pagrindinis",
	"PATH",
	"HTTP_CACHE_CONTROL",
	"SERVER_SOFTWARE",
	"DOCUMENT_ROOT",
	"REMOTE_PORT",
	"SCRIPT_FILENAME",
	"max-age",
	"PHPSESSID",
	"GLOBALS",
	"_REQUEST",
	"HTTP_POST_FILES",
	"HTTP_COOKIE_VARS",
	"HTTP_SERVER_VARS",
	"HTTP_ENV_VARS",
	"HTTP_SESSION_VARS",
	"_ENV","PHPSESSID",
	"SESS_DBUSER",
	"SESS_DBPASS",
	"HTTP_COOKIE");
	$timestamp=date("m/d/y h:m:s");
	$message="<div class=\"title\">Kintamieji - sugeneruota: $timestamp</div>\n";
	$sql_error=mysql_error();
	if($sql_error){
		$message.="\n<div class=\"title\">Paskutine Mysql Klaida:</div>\n<div class=\"sarasas\">".mysql_error()."</div>\n";
	}
	foreach($defined_vars as $key=>$val) {
		if(is_array($val) && !in_array($key,$ignorelist) && count($val) > 0) {
			$message.="\n<div class=\"title\"><b>$".$key."</b> array (key=value):</div>\n";
			foreach($val as $subkey=>$subval) {
				if(!in_array($subkey,$ignorelist) && !is_array($subval)) {
					$message.="<div class=\"sarasas\"><b>['".$subkey."']</b> = ".((is_array($subval))?$subval:nl2br(htmlspecialchars($subval)))."</div>\n";
				}
				elseif(!in_array($subkey,$ignorelist) && is_array($subval)) {
					foreach($subval as $subsubkey=>$subsubval) {
						if(!in_array($subsubkey,$ignorelist)) {
							$message.="<div class=\"sarasas\"><b>['".$subsubkey."']</b> = ".((is_array($subsubval))?$subsubval:nl2br(htmlspecialchars($subsubval)))."</div>\n";
						}
					}
					$message .= "<br/>\n";
				}
			}
			$message .= "<br/>\n";
		}
		elseif(!is_array($val) && !in_array($key,$ignorelist) && $val) {
			$message.="\n<div class=\"sarasas\"><b>$".$key."</b> = ".( (is_array($val) || !is_string($val)) ? nl2br(implode('',$val)) : nl2br(htmlspecialchars($val)))."</div>\n";
			//$message.="\n<div class=\"sarasas\"><b>$".$key."</b> = ".( is_array($val) ? print_rr($val) : nl2br(htmlspecialchars($val)) )."</div>\n";
		}
	}
	echo $message;
}
?>
